package com.transsion.testing.callstate;

import android.Manifest;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import me.weyye.hipermission.HiPermission;
import me.weyye.hipermission.PermissionCallback;
import me.weyye.hipermission.PermissionItem;

public class MainActivity extends AppCompatActivity {
    Button button;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button= (Button) findViewById(R.id.button);
        textView= (TextView) findViewById(R.id.textview);
        handlePermission();
    }

    private void handlePermission() {
        List<PermissionItem> permissionItems = new ArrayList<>();
        permissionItems.add(new PermissionItem(Manifest.permission.READ_PHONE_STATE, "获取电话状态", R.drawable.permission_ic_phone));
        permissionItems.add(new PermissionItem(Manifest.permission.PROCESS_OUTGOING_CALLS, "获取拨打电话号码", R.drawable.permission_ic_location));


        HiPermission.create(this)
                .permissions(permissionItems)
                .checkMutiPermission(new PermissionCallback() {
                    @Override
                    public void onClose() {
                    }


                    @Override
                    public void onFinish() {
                    }


                    @Override
                    public void onDeny(String permission, int position) {
                    }


                    @Override
                    public void onGuarantee(String permission, int position) {


                    }
                });


    }
    public void start(View view){
        Intent startserviceintent=new Intent(this,phoneservice.class);
        startService(startserviceintent);
        button.setText("开启监听服务");
        button.setEnabled(false);
    }
}
